use eframe::egui::{self};
use egui::Vec2;
use serde::{Deserialize, Serialize};

use crate::IndexState;

#[derive(Clone, Debug)]
pub struct Login {
    pub username: String,
    pub password: String,
    pub login_result: bool,
    pub state: IndexState,
}

impl Login {
    pub fn new() -> Login {
        Login {
            username: String::new(),
            password: String::new(),
            login_result: false,
            state:IndexState::IndexState
        }
    }
    pub fn show(&mut self, ctx: &egui::Context) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.add_space(ui.available_height() / 3.0);
            ui.vertical_centered(|ui| {
                ui.group(|ui| {
                    ui.set_max_width(400f32);
                    ui.spacing_mut().item_spacing = Vec2 { x: 30f32, y: 30f32 };
                    ui.heading(egui::RichText::new("XXX系统平台"));

                    ui.label("用 户 名 称:");
                    ui.text_edit_singleline(&mut self.username);

                    ui.label("密 码:");
                    ui.text_edit_singleline(&mut self.password);
                    ui.add_space(30f32);

                    if ui.button("登 录").clicked() {
                        self.state = IndexState::IndexState;
                        self.login_result = true;
                    }
                });
            });
        });
    }
}
